package com.ymatou.app.api.service;

import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * App登陆Call FreeMaker Template自动生成代码
 */
public class AppLoginCall extends YmatouBaseCall {
	private static String opurl = "api/User/LoginAuth";

	public AppLoginCall() {
		super(EnvSetup.getSystemUrl("api_app"), opurl, "POST", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	}

	/**
	 * 获取Data
	 * 
	 * @return Data
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Data = jo.getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取UserId
	 */
	public int getUserId() {
		int UserId = 0;
		try {
			UserId = getData().getInt("UserId");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return UserId;
	}

	/**
	 * 获取AccessToken
	 */
	public String getAccessToken() {
		String AccessToken = null;
		try {
			AccessToken = getData().get("AccessToken").toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return AccessToken;
	}
}